package com.my.json.sensitive.config.handle;

import com.my.json.sensitive.config.AbstractSensitiveHandler;
import com.my.json.sensitive.enums.SensitiveType;
import org.apache.commons.lang3.StringUtils;

/**
 * @description 手机号脱敏
 * @author hexinglin
 * @created 2021-12-29 15:33
 **/
public class MobilePhoneSensitiveHandler extends AbstractSensitiveHandler {
    public MobilePhoneSensitiveHandler() {
    }

    @Override
    public SensitiveType strategy() {
        return SensitiveType.MOBILE_PHONE;
    }
    @Override
    public String sensitive(String text) {
        if (StringUtils.isBlank(text)) {
            return "";
        } else {
            int length = StringUtils.length(text);
            if (length < 7) {
                return text;
            } else {
                String left = StringUtils.left(text, 3);
                String right = StringUtils.right(text, 4);
                return left.concat(StringUtils.leftPad(right, 8, '*'));
            }
        }
    }
}

